<?php

namespace Extend\Sign;

/**
 * 排序参数后进行签名
 */
class SortSign{
    
    /**
     * 生成签名
     */
    public static function makeSign($params, $signkey){
        // 按键名a-z升序
        ksort($params); 
        reset($params);
        $sign = '';
        foreach($params as $k => $v){
            $sign .=  $k . '=' . $v;
        }
// var_dump($sign,$signkey);
        return md5($sign.$signkey);
    }

    /**
     * 验证签名
     */
    public static function checkSign($params, $sign, $signkey){
        $localSign = self::makeSign($params, $signkey);
        if($localSign == $sign){
            return true;
        }

        return false;
    }

}